/*
 * @Description: 命名空间
 * @Autor: HuiSir<273250950@qq.com>
 * @Date: 2021-05-06 18:41:05
 * @LastEditTime: 2021-05-20 16:03:50
 */
/**
 *  定义
 *  “命名空间”在1.5版本之前叫“内部模块”，是相对于“外部模块”而命名的。
 *  命名空间是为了与 ECMAScript 2015里的术语保持一致，推荐的写法 namespace X {}
 *  命名空间实际上就是ts文件内部的模块。内部模块的作用是为了记录对象类型的同时还不用担心与其它对象产生命名冲突,这样就避免了全局命名的混乱。
 */
var Validation;
(function (Validation) {
    var lettersRegexp = /^[A-Za-z]+$/;
    var numberRegexp = /^[0-9]+$/;
    var LettersOnlyValidator = /** @class */ (function () {
        function LettersOnlyValidator() {
        }
        LettersOnlyValidator.prototype.isAcceptable = function (s) {
            return lettersRegexp.test(s);
        };
        return LettersOnlyValidator;
    }());
    Validation.LettersOnlyValidator = LettersOnlyValidator;
    var ZipCodeValidator = /** @class */ (function () {
        function ZipCodeValidator() {
        }
        ZipCodeValidator.prototype.isAcceptable = function (s) {
            return s.length === 5 && numberRegexp.test(s);
        };
        return ZipCodeValidator;
    }());
    Validation.ZipCodeValidator = ZipCodeValidator;
})(Validation || (Validation = {}));
// Some samples to try
var strings = ["Hello", "98052", "101"];
/*
 命名空间的使用
 命名空间内的变量需要【命名空间.导出的变量名】来使用
 */
var validators = {};
validators["ZIP code"] = new Validation.ZipCodeValidator();
validators["Letters only"] = new Validation.LettersOnlyValidator();
/* --------------------------------------------------- */
/* ------------------LettersOnlyValidator.ts----------------- */
/// <reference path="Validation.ts" />
(function (Validation) {
    var lettersRegexp = /^[A-Za-z]+$/;
    var LettersOnlyValidator = /** @class */ (function () {
        function LettersOnlyValidator() {
        }
        LettersOnlyValidator.prototype.isAcceptable = function (s) {
            return lettersRegexp.test(s);
        };
        return LettersOnlyValidator;
    }());
    Validation.LettersOnlyValidator = LettersOnlyValidator;
})(Validation || (Validation = {}));
/* ----------------------------------------------------------- */
/* ----------------------Test.ts----------------------------- */
/// <reference path="Validation.ts" />
/// <reference path="LettersOnlyValidator.ts" />
/// <reference path="ZipCodeValidator.ts" />
// Some samples to try
var strings = ["Hello", "98052", "101"];
// Validators to use
var validators = {};
validators["ZIP code"] = new Validation.ZipCodeValidator();
validators["Letters only"] = new Validation.LettersOnlyValidator();
/* ----------------------------------------------------------- */
/**
 * 当涉及到多文件时，我们必须确保所有编译后的代码都被加载了。 我们有两种方式。
 * > 把所有的输入文件编译为一个输出文件，需要使用--outFile标记：`tsc --outFile sample.js Test.ts`
 */
/**
 * 命名空间别名
 * 使用import关键字可以为命名空间内的变量创建别名，注意这种方式区别与导入模块
 */
var Shapes;
(function (Shapes) {
    var Polygons;
    (function (Polygons) {
        var Triangle = /** @class */ (function () {
            function Triangle() {
            }
            return Triangle;
        }());
        Polygons.Triangle = Triangle;
        var Square = /** @class */ (function () {
            function Square() {
            }
            return Square;
        }());
        Polygons.Square = Square;
    })(Polygons = Shapes.Polygons || (Shapes.Polygons = {}));
})(Shapes || (Shapes = {}));
var polygons = Shapes.Polygons;
var sq = new polygons.Square();
